namespace DotNetNuke.UI.WebControls
{
    using Microsoft.VisualBasic;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Collections;
    using System.Reflection;
    using System.Xml;

    public class MenuNodeCollection : DNNNodeCollection
    {
        private DNNMenu m_objDNNMenu;

        public MenuNodeCollection(string strNamespace, DNNMenu objControl) : base(strNamespace)
        {
            this.m_objDNNMenu = objControl;
        }

        public MenuNodeCollection(XmlNode objXmlNode, DNNMenu objControl) : base(objXmlNode)
        {
            this.m_objDNNMenu = objControl;
        }

        public MenuNodeCollection(string strXML, string strXSLFile, DNNMenu objControl) : base(strXML, strXSLFile)
        {
            this.m_objDNNMenu = objControl;
        }

        public int Add()
        {
            return this.Add("");
        }

        public int Add(MenuNode objNode)
        {
            int num2 = base.Add(objNode);
            objNode.SetDNNMenu(this.m_objDNNMenu);
            if (Strings.Len(objNode.ID) == 0)
            {
                objNode.ID = objNode.ParentNameSpace + "_" + StringType.FromInteger(objNode.GetHashCode());
            }
            return num2;
        }

        public int Add(string strText)
        {
            MenuNode objNode = new MenuNode();
            int num2 = this.Add(objNode);
            objNode.Text = strText;
            return num2;
        }

        public int Add(string strID, string strKey, string strText, string strNavigateURL)
        {
            return this.Add(strID, strKey, strText, strNavigateURL, "", "", "", true, "", "", "", false, eClickAction.Navigate, "", -1);
        }

        public int Add(string strID, string strKey, string strText, string strNavigateURL, string strJSFunction, string strTarget, string strToolTip, bool blnEnabled, string strCSSClass, string strCSSClassSelected, string strCSSClassHover, bool blnSelected, eClickAction enumClickAction, string strCssClassOver, int intImageIndex)
        {
            int num2 = this.Add();
            MenuNode node = this[num2];
            if (Strings.Len(strID) > 0)
            {
                node.ID = strID;
            }
            else
            {
                node.ID = node.ParentNameSpace + "_" + StringType.FromInteger(this.XMLNode.ChildNodes.Count);
            }
            node.Key = strKey;
            node.Text = strText;
            node.NavigateURL = strNavigateURL;
            node.JSFunction = strJSFunction;
            node.Target = strTarget;
            node.ToolTip = strToolTip;
            node.Enabled = blnEnabled;
            node.CSSClass = strCSSClass;
            node.CSSClassSelected = strCSSClassSelected;
            node.CSSClassHover = strCSSClassHover;
            node.Selected = blnSelected;
            node.ClickAction = enumClickAction;
            node.CssClassOver = strCssClassOver;
            node.ImageIndex = intImageIndex;
            return num2;
        }

        public bool Contains(MenuNode value)
        {
            if (this.FindNode(value.ID) == null)
            {
                return false;
            }
            return true;
        }

        public MenuNode FindNode(string ID)
        {
            XmlNode objXmlNode = this.XMLNode.SelectSingleNode("//n[@id='" + ID + "']");
            if (objXmlNode != null)
            {
                return new MenuNode(objXmlNode, this.m_objDNNMenu);
            }
            return null;
        }

        public MenuNode FindNodeByKey(string Key)
        {
            XmlNode objXmlNode = this.XMLNode.SelectSingleNode("//n[@key='" + Key + "']");
            if (objXmlNode != null)
            {
                return new MenuNode(objXmlNode, this.m_objDNNMenu);
            }
            return null;
        }

        public override Collection FindSelectedNodes()
        {
            Collection collection = new Collection();
            if (this.XMLNode != null)
            {
                XmlNodeList list = this.XMLNode.SelectNodes("//n[@selected='1']");
                foreach (XmlNode node in list)
                {
                    collection.Add(new MenuNode(node, this.m_objDNNMenu), null, null, null);
                }
            }
            return collection;
        }

        public IEnumerator GetEnumerator()
        {
            return new MenuNodeEnumerator(this.XMLNode, this.m_objDNNMenu);
        }

        public int IndexOf(MenuNode value)
        {
            int num2 = 0; ;
            int count = this.XMLNode.ChildNodes.Count;
            for (int i = 0; i <= count; i++)
            {
                if (StringType.StrCmp(new MenuNode(this.XMLNode.ChildNodes[i], this.m_objDNNMenu).ID, value.ID, false) == 0)
                {
                    return i;
                }
            }
            return num2;
        }

        public void Insert(int index, MenuNode value)
        {
            this.XMLNode.InsertAfter(this.XMLNode.ChildNodes[index], value.XmlNode);
        }

        public void Remove(MenuNode value)
        {
            this.XMLNode.RemoveChild(value.XmlNode);
        }

        public MenuNode this[int index]
        {
            get
            {
                return new MenuNode(this.XMLNode.ChildNodes[index], this.m_objDNNMenu);
            }
            set
            {
                throw new Exception("Cannot Assign Node Directly");
            }
        }
    }
}

